<?php
namespace app\common\component\user_platoon;

use app\common\model\UserPlatoon;

class UserPlatoonService {
	public function getUserPlatoonId($user_id) {
		$getUserPlatoon = UserPlatoon::get(['user_id' => $user_id]);

		if($getUserPlatoon) {
			return [
				'code' => 0,
				'data' => [
					'user_platoon' => $getUserPlatoon
				]
			];
		} else {
			return $this -> create([
				'user_id' => $user_id,
				'price' => 0
			]);
		}
	}

	public function create($data) {
		$UserPlatoon = new UserPlatoon($data);

		if($UserPlatoon -> save()) {
    		return [
    			'code' => 0,
    			'message' => '创建排单币成功',
    			'data' => [
    				'user_platoon' => $UserPlatoon
    			]
    		];
    	}

    	return [
			'code' => -1,
			'message' => '创建排单币失败'
		];
	}
}
?>